package net.csdn.business.discuss.common.dto.converter;


import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import net.csdn.business.discuss.common.dto.PageRequestDTO;

import java.util.List;


/**
 *  @author: zhangyalei
 *  @Date: 2021/11/2 10:53
 *  @Description: DefaultPageQueryDTO
 */
public class PageQueryConverter {

    public static Page convertToPage(PageRequestDTO pageQueryDTO) {
        Page page = new Page(pageQueryDTO.getPage(), pageQueryDTO.getSize());
        //设置排序类型
        List<OrderItem> list = Lists.newArrayList();
        pageQueryDTO.getSorts().forEach(sort -> {
            OrderItem orderItem = new OrderItem();
            orderItem.setColumn(sort.getProperty());
            orderItem.setAsc(sort.getDirection().ordinal() == 0);
            list.add(orderItem);
        });
        page.setOrders(list);
        return page;
    }

}
